package stu.day19_day24.day20;

import java.util.Arrays;

public class LeetCode134 {
    public int canCompleteCircuit(int[] gas, int[] cost) {

        int x = Arrays.stream(gas).map(Integer::valueOf).reduce(0,Integer::sum);
        int y = Arrays.stream(cost).reduce(0,Integer::sum);
        int num = 0;
        int tep = 0;

        if(y>x){
            return -1;
        }else {
            for(int i=0;i<gas.length;i++){
                tep += gas[i]-cost[i];
                if(tep<0){
                    num = i+1;
                    tep = 0;
                }
            }

        return  num;




        }







    }


}
